package com.jackie.trpc.service.impl;

import com.jackie.trpc.service.DataServiceAPI;
import com.jackie.trpc.service.TrpcDemo;
import com.jackie.trpc.service.TrpcDemo.ProcessDataRequest;
import com.jackie.trpc.service.TrpcDemo.ProcessDataResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.google.protobuf.InvalidProtocolBufferException;
import com.tencent.trpc.core.rpc.RpcContext;



@Service
public class DataServiceAPIImpl implements DataServiceAPI {

    @Autowired
    private RedisTemplate<String, byte[]> redisTemplate;

    @Override
    public ProcessDataResponse processData(RpcContext context, ProcessDataRequest request) {
        byte[] dataByte=redisTemplate.opsForValue().get(request.getRedisKey());
        TrpcDemo.mydata mydata=null;
        try {
            mydata=TrpcDemo.mydata.parseFrom(dataByte);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        return ProcessDataResponse.newBuilder().setContent(mydata.toByteString()).build();
    }

    // @Override
    // public Byte[] processData(RpcContext context, TrpcDemo.ProcessDataRequest request) {
    //     byte[] dataByte=redisTemplate.opsForValue().get(request.getRedisKey());
    
    // }
}
